package com.han.shadow.customerapp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.han.shadow.customerapp.R;
import com.han.shadow.customerapp.http.Connector;
import com.han.shadow.customerapp.mystatic.MyScreen;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

public class LoginActivity extends AppCompatActivity {
    private EditText etName;
    private EditText etPsd;
    private String account;
    private String psd;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();

    }

    private void initView() {
        etName = (EditText) findViewById(R.id.et_login_username);
        etPsd = (EditText) findViewById(R.id.et_login_password);
    }

    private final Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            if(msg.what == 1){
                Intent intent = new Intent();
                intent.setClass(LoginActivity.this,MainActivity.class);
                startActivity(intent);
            }

        }
    };

    //登录
    public void btnSignIn(View view){
        new Thread(new Runnable() {
            @Override
            public void run() {
                Connector conn = new Connector();
                account = etName.getText().toString();
                psd = etPsd.getText().toString();
                MyScreen.cid = conn.login(account, psd);
                if(MyScreen.cid != null && !MyScreen.cid.equals("")){
                    handler.sendEmptyMessage(1);
                }
//                else{
//                    Toast.makeText(LoginActivity.this,"用户名或者密码输入有误",Toast.LENGTH_SHORT).show();
//                }
            }
        }).start();

    }



}
